package com.randi.system.domain.entity.sysDict;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.randi.common.core.domain.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.annotation.Transient;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * @author ziye
 */
@EqualsAndHashCode(callSuper = true)
@Data
@TableName("sys_dict_data")
@ApiModel(value = "SysDictData", description = "字典数据对象")
public class SysDictData extends BaseEntity {

    @TableId(value = "data_id", type = IdType.AUTO)
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "数据编码")
    private Long dataId;

    @NotNull(message = "字典ID不能为空")
    @TableField(value = "dict_id")
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "字典ID")
    private Long dictId;

    @TableField(value = "`data_sort`")
    @ApiModelProperty(value = "数据排序")
    private Integer dataSort;

    @NotEmpty(message = "数据标签不能为空")
    @TableField(value = "`data_label`")
    @ApiModelProperty(value = "数据标签")
    private String dataLabel;

    @NotEmpty(message = "数据键值不能为空")
    @TableField(value = "`data_value`")
    @ApiModelProperty(value = "数据键值")
    private String dataValue;

    @TableField(value = "`css_class`")
    @ApiModelProperty(value = "样式属性（其他样式扩展）")
    private String cssClass;

    @TableField(value = "`list_class`")
    @ApiModelProperty(value = "表格回显样式")
    private String listClass;

    @TableField(value = "`is_default`")
    @ApiModelProperty(value = "是否默认（0是 1否）")
    private Integer isDefault;

    @Transient
    public String getKey() {
        return this.dataId == null ? "" : this.dataId.toString();
    }

    @Transient
    public String getStatusName() {
        return getStatus() == null || getStatus() == 0 ? "正常" : "停用";
    }


}
